<?php 
/* 	These code was generated using phpCIGen v 2.a (21/05/2012)
	#zaqi 		zaqi.smart@gmail.com,http://zenzaqi.blogspot.com,
    #CV. Trust Solution, jl. Saronojiwo 2/19 Surabaya, http://www.ts.co.id

	+ Module  		: t_project Model
	+ Description	: For record model process back-end
	+ Filename 		: c_t_project.php
 	+ creator 		: 
 	+ Created on 24/Jul/2012 10:52:52

*/

class M_t_project extends CI_Model{

		//constructor
		function __construct() {
			parent::__construct();
		}

		//function for get list record
		function t_project_list($filter,$start,$end){
			$sql = "SELECT project_id, project_flag, project_code, IF(project_type=1, 'Regular', 'Join Operation') AS project_type,
					project_name, project_shortname, project_pm, project_semcm, project_value, project_value - (((SELECT nvalue1 FROM m_setup WHERE setup_id = 1) * project_value ) div (100 + (SELECT nvalue1 FROM m_setup WHERE setup_id = 1) )) AS project_value_minusppn,
					project_start AS project_start_str,IF(DATE_FORMAT(project_start,'%Y-%m-%d')='1970-01-01','',project_start) AS project_start,
					project_p1 AS project_p1_str,IF((DATE_FORMAT(project_p1,'%Y-%m-%d')='1970-01-01' OR DATE_FORMAT(project_p1,'%Y-%m-%d')='0000-00-00'),'',project_p1) AS project_p1,
					project_p2 AS project_p2_str,IF((DATE_FORMAT(project_p2,'%Y-%m-%d')='1970-01-01' OR DATE_FORMAT(project_p2,'%Y-%m-%d')='0000-00-00'),'',project_p2) AS project_p2,
					branch_id, branch_name, div_id, div_name
					FROM t_project JOIN m_branch ON(m_branch.branch_id = t_project.m_branch_id)
					LEFT JOIN m_div ON(m_div.div_id = t_project.m_div_id)";

			// For simple search
			if ($filter<>""){
				$sql .=preg_match("/WHERE/i",$sql)? " WHERE ":" WHERE ";
				$sql .= " (project_code LIKE '%".addslashes($filter)."%' OR
						lower(project_name) LIKE '%".addslashes(strtolower($filter))."%' OR
						lower(project_shortname) LIKE '%".addslashes(strtolower($filter))."%'  OR
						lower(project_pm) LIKE '%".addslashes(strtolower($filter))."%' OR
						lower(project_semcm) LIKE '%".addslashes(strtolower($filter))."%' OR
						lower(project_value) LIKE '%".addslashes(strtolower($filter))."%' OR
						lower(project_start) LIKE '%".addslashes(strtolower($filter))."%' OR
						lower(project_p1) LIKE '%".addslashes(strtolower($filter))."%' OR
						lower(branch_name) LIKE '%".addslashes(strtolower($filter))."%' OR
						lower(project_p2) LIKE '%".addslashes(strtolower($filter))."%' OR
						lower(div_name) LIKE '%".addslashes(strtolower($filter))."%' )";
			}
			$result = $this->db->query($sql);
			$nbrows = $result->num_rows();
			$limit = $sql." LIMIT ".$start.", ".$end;
			$result = $this->db->query($limit);

			if($nbrows>0){
				foreach($result->result() as $row){
					$arr[] = $row;
				}
				$jsonresult = json_encode($arr);
				return '({"total":"'.$nbrows.'","results":'.$jsonresult.'})';
			} else {
				return '({"total":"0", "results":""})';
			}
		}

		//function for create new record
		function t_project_create($m_branch, $project_type, $project_code, $project_name, $project_shortname, $project_pm, $project_semcm,
				$project_value, $project_value_minusppn, $project_start, $project_p1, $project_p2, $project_div, $project_created_date, $project_created_by){
			$data = array(
					"project_code"=>$project_code,
					"project_type"=>$project_type,
					"project_name"=>$project_name,
					"project_shortname"=>$project_shortname,
					"project_pm"=>$project_pm,
					"project_semcm"=>$project_semcm,
					"project_value"=>$project_value,
					"project_start"=>$project_start,
					"project_p1"=>$project_p1,
					"project_p2"=>$project_p2,
					"project_created_date"=>$project_created_date,
					"project_created_by"=>$project_created_by,
					"project_updated_count"=>0,
					"m_branch_id"=>$m_branch,
					"m_div_id"=>$project_div
					);
			$this->db->insert('t_project', $data);
			if($this->db->affected_rows())
				return '1';
			else
				return '0';
		}

		//function for update record
		function t_project_update($m_branch,$project_id,$project_flag,$project_code,$project_type,$project_name,$project_shortname,$project_pm,$project_semcm,
				$project_value,$project_start,$project_p1,$project_p2,$project_div,
				$project_updated_date,$project_updated_by){
			$data = array(
						//"project_id"=>$project_id,
						//"project_flag"=>$project_flag,
						"project_code"=>$project_code,
						"project_name"=>$project_name,
						"project_shortname"=>$project_shortname,
						"project_pm"=>$project_pm,
						"project_semcm"=>$project_semcm,
						"project_value"=>$project_value,
						"project_start"=>$project_start,
						"project_p1"=>$project_p1,
						"project_p2"=>$project_p2,
						"project_updated_date"=>$project_updated_date,
						"project_updated_by"=>$project_updated_by
					);
			
			if(is_numeric($m_branch)){
				$sql_branch = "SELECT branch_id FROM m_branch WHERE branch_id=".$m_branch." LIMIT 1";
				$rs_branch = $this->db->query($sql_branch);
				if($rs_branch->num_rows()){
					$row = $rs_branch->row();
					$data['m_branch_id'] = $row->branch_id;
				}
			}
			
			if(is_numeric($project_div)){
				$sql_div = "SELECT div_id FROM m_div WHERE div_id=".$project_div." LIMIT 1";
				$rs_div = $this->db->query($sql_div);
				if($rs_div->num_rows()){
					$row = $rs_div->row();
					$data['m_div_id'] = $row->div_id;
				}
			}
			
			if(is_numeric($project_type)){
				$data["project_type"] = $project_type;
			}
			$this->db->where('project_id',$project_id);
			$this->db->update('t_project', $data);
			
			if($this->db->affected_rows()){
				$sqlu = "UPDATE t_project SET project_updated_count = project_updated_count+1 WHERE project_id=".$project_id;
				$this->db->query($sqlu);
				
				return '1';
			}else{
				return '0';
			}
			
		}

		//fcuntion for delete record
		function t_project_delete($pkid){
			// You could do some checkups here and return '0' or other error consts.
			// Make a single query to delete all of the t_projects at the same time :
			if(sizeof($pkid)<1){
				return '0';
			} else if (sizeof($pkid) == 1){
				$sql = "SELECT t_rapk.t_project_id  FROM t_rapk WHERE t_project_id = ".$pkid[0];
				$query = $this->db->query($sql);
				if ($query->num_rows() == 0 ){
					$sql = "DELETE FROM t_project WHERE project_id = ".$pkid[0];
					$this->db->query($sql);
					return '1';
				}else{
					return '3';
				}
			} else {
				$sql_check = "SELECT t_rapk.t_project_id  FROM t_rapk WHERE "; // t_project_id = ".$pkid[0];
				$sql = "DELETE FROM t_project WHERE ";
				for($i = 0; $i < sizeof($pkid); $i++){
					$sql = $sql . "project_id= ".$pkid[$i];
					if($i<sizeof($pkid)-1){
						$sql = $sql . " OR ";
					}
					
					$sql_check = $sql_check . "project_id= ".$pkid[$i];
					if($i<sizeof($pkid)-1){
						$sql_check = $sql_check . " OR ";
					}
				}
				$query = $this->db->query($sql_check);
				if ($query->num_rows() == 0 ){
					$this->db->query($sql);
					return '1';
				}else{
					return '3';
				}
			}
		}

		//function for advanced search record
		function t_project_search($project_id,
				 $project_flag,
				 $project_code,
				 $project_type,
				 $project_name,
				 $project_shortname,
				 $project_pm,
				 $project_semcm,
				 $project_value,
				 $project_start,
				 $project_p1,
				 $project_p2,
				 $project_created_date,
				 $project_created_by,
				 $project_updated_date,
				 $project_updated_by,
				 $project_updated_count,
				 $m_branch,$start,$end){
			//full query
			$sql = "SELECT project_id,
						   project_flag,
						   project_code,
						   project_type,
						   project_name,
						   project_shortname,
						   project_pm,
						   project_semcm,
						   project_value,
						   project_start,
						   project_p1,
						   project_p2,
						   project_created_date,
						   project_created_by,
						   project_updated_date,
						   project_updated_by,
						   project_updated_count,
						   m_branch_id
					FROM   t_project";

			if($project_id!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(project_id) LIKE '%".addslashes(strtolower($project_id))."%'";
			};
			if($project_flag!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(project_flag) LIKE '%".addslashes(strtolower($project_flag))."%'";
			};
			if($project_code!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(project_code) LIKE '%".addslashes(strtolower($project_code))."%'";
			};
			if($project_type!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(project_type) LIKE '%".addslashes(strtolower($project_type))."%'";
			};
			if($project_name!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(project_name) LIKE '%".addslashes(strtolower($project_name))."%'";
			};
			if($project_shortname!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(project_shortname) LIKE '%".addslashes(strtolower($project_shortname))."%'";
			};
			if($project_pm!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(project_pm) LIKE '%".addslashes(strtolower($project_pm))."%'";
			};
			if($project_semcm!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(project_semcm) LIKE '%".addslashes(strtolower($project_semcm))."%'";
			};
			if($project_value!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(project_value) LIKE '%".addslashes(strtolower($project_value))."%'";
			};
			if($project_start!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(project_start) LIKE '%".addslashes(strtolower($project_start))."%'";
			};
			if($project_p1!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(project_p1) LIKE '%".addslashes(strtolower($project_p1))."%'";
			};
			if($project_p2!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(project_p2) LIKE '%".addslashes(strtolower($project_p2))."%'";
			};
			if($project_created_date!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(project_created_date) LIKE '%".addslashes(strtolower($project_created_date))."%'";
			};
			if($project_created_by!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(project_created_by) LIKE '%".addslashes(strtolower($project_created_by))."%'";
			};
			if($project_updated_date!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(project_updated_date) LIKE '%".addslashes(strtolower($project_updated_date))."%'";
			};
			if($project_updated_by!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(project_updated_by) LIKE '%".addslashes(strtolower($project_updated_by))."%'";
			};
			if($project_updated_count!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(project_updated_count) LIKE '%".addslashes(strtolower($project_updated_count))."%'";
			};
			if($m_branch!=''){
				$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
				$sql.= " lower(m_branch_id) LIKE '%".addslashes(strtolower($m_branch))."%'";
			};

			$result = $this->db->query($sql);
			$nbrows = $result->num_rows();
			$limit = $sql." LIMIT ".$start.",".$end;
			$result = $this->db->query($limit);

			if($nbrows>0){
				foreach($result->result() as $row){
					$arr[] = $row;
				}
				$jsonresult = json_encode($arr);
				return '({"total":"'.$nbrows.'","results":'.$jsonresult.'})';
			} else {
				return '({"total":"0", "results":""})';
			}
		}

		//function for print record
		function t_project_print($project_id,
				 $project_flag,
				 $project_code,
				 $project_type,
				 $project_name,
				 $project_shortname,
				 $project_pm,
				 $project_semcm,
				 $project_value,
				 $project_start,
				 $project_p1,
				 $project_p2,
				 $project_created_date,
				 $project_created_by,
				 $project_updated_date,
				 $project_updated_by,
				 $project_updated_count,
				 $m_branch,$option,$filter){
			//full query
			/* $sql = "SELECT project_id,
						   project_flag,
						   project_code,
						   project_type,
						   project_name,
						   project_shortname,
						   project_pm,
						   project_semcm,
						   project_value,
						   project_start,
						   project_p1,
						   project_p2,
						   project_created_date,
						   project_created_by,
						   project_updated_date,
						   project_updated_by,
						   project_updated_count,
						   m_branch_id
				    FROM   t_project"; */
			$sql = "SELECT project_id, project_flag, project_code, IF(project_type=1, 'Regular', 'Join Operation') AS project_type,
					project_name, project_shortname, project_pm, project_semcm, project_value, project_value - (((SELECT nvalue1 FROM m_setup WHERE setup_id = 1) * project_value ) div 100) AS project_value_minusppn,
					project_start, project_p1, project_p2, branch_id, branch_name, div_id, div_name
					FROM t_project JOIN m_branch ON(m_branch.branch_id = t_project.m_branch_id)
					LEFT JOIN m_div ON(m_div.div_id = t_project.m_div_id)";

			if($option=='LIST'){
				$sql .=preg_match("/WHERE/i",$sql)? " AND ":" WHERE ";
				$sql .= " (lower(project_id) LIKE '%".addslashes(strtolower($filter))."%' OR lower(project_flag) LIKE '%".addslashes(strtolower($filter))."%' OR lower(project_code) LIKE '%".addslashes(strtolower($filter))."%' OR lower(project_type) LIKE '%".addslashes(strtolower($filter))."%' OR lower(project_name) LIKE '%".addslashes(strtolower($filter))."%' OR lower(project_shortname) LIKE '%".addslashes(strtolower($filter))."%' OR lower(project_pm) LIKE '%".addslashes(strtolower($filter))."%' OR lower(project_semcm) LIKE '%".addslashes(strtolower($filter))."%' OR lower(project_value) LIKE '%".addslashes(strtolower($filter))."%' OR lower(project_start) LIKE '%".addslashes(strtolower($filter))."%' OR lower(project_p1) LIKE '%".addslashes(strtolower($filter))."%' OR lower(project_p2) LIKE '%".addslashes(strtolower($filter))."%' OR lower(project_created_date) LIKE '%".addslashes(strtolower($filter))."%' OR lower(project_created_by) LIKE '%".addslashes(strtolower($filter))."%' OR lower(project_updated_date) LIKE '%".addslashes(strtolower($filter))."%' OR lower(project_updated_by) LIKE '%".addslashes(strtolower($filter))."%' OR lower(project_updated_count) LIKE '%".addslashes(strtolower($filter))."%' OR lower(m_branch_id) LIKE '%".addslashes(strtolower($filter))."%' )";
			} else if($option=='SEARCH'){
				if($project_id!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_id) LIKE '%".addslashes(strtolower($project_id))."%'";
				};
				if($project_flag!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_flag) LIKE '%".addslashes(strtolower($project_flag))."%'";
				};
				if($project_code!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_code) LIKE '%".addslashes(strtolower($project_code))."%'";
				};
				if($project_type!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_type) LIKE '%".addslashes(strtolower($project_type))."%'";
				};
				if($project_name!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_name) LIKE '%".addslashes(strtolower($project_name))."%'";
				};
				if($project_shortname!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_shortname) LIKE '%".addslashes(strtolower($project_shortname))."%'";
				};
				if($project_pm!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_pm) LIKE '%".addslashes(strtolower($project_pm))."%'";
				};
				if($project_semcm!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_semcm) LIKE '%".addslashes(strtolower($project_semcm))."%'";
				};
				if($project_value!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_value) LIKE '%".addslashes(strtolower($project_value))."%'";
				};
				if($project_start!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_start) LIKE '%".addslashes(strtolower($project_start))."%'";
				};
				if($project_p1!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_p1) LIKE '%".addslashes(strtolower($project_p1))."%'";
				};
				if($project_p2!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_p2) LIKE '%".addslashes(strtolower($project_p2))."%'";
				};
				if($project_created_date!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_created_date) LIKE '%".addslashes(strtolower($project_created_date))."%'";
				};
				if($project_created_by!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_created_by) LIKE '%".addslashes(strtolower($project_created_by))."%'";
				};
				if($project_updated_date!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_updated_date) LIKE '%".addslashes(strtolower($project_updated_date))."%'";
				};
				if($project_updated_by!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_updated_by) LIKE '%".addslashes(strtolower($project_updated_by))."%'";
				};
				if($project_updated_count!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_updated_count) LIKE '%".addslashes(strtolower($project_updated_count))."%'";
				};
				if($m_branch!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(m_branch_id) LIKE '%".addslashes(strtolower($m_branch))."%'";
				};
			}
			$query = $this->db->query($sql);
			return $query->result();
		}

		//function  for export to excel
		function t_project_export_excel($project_id ,$project_flag ,$project_code ,$project_type ,$project_name ,$project_shortname ,$project_pm ,$project_semcm ,$project_value ,$project_start ,$project_p1 ,$project_p2 ,$project_created_date ,$project_created_by ,$project_updated_date ,$project_updated_by ,$project_updated_count ,$m_branch ,$option,$filter){
			//full query
			/* $sql = "SELECT project_id,
						   project_flag,
						   project_code,
						   project_type,
						   project_name,
						   project_shortname,
						   project_pm,
						   project_semcm,
						   project_value,
						   project_start,
						   project_p1,
						   project_p2,
						   project_created_date,
						   project_created_by,
						   project_updated_date,
						   project_updated_by,
						   project_updated_count,
						   m_branch_id				    FROM   t_project"; */
			$sql = "SELECT project_id, project_flag, project_code, IF(project_type=1, 'Regular', 'Join Operation') AS project_type,
					project_name, project_shortname, project_pm, project_semcm, project_value, project_value - (((SELECT nvalue1 FROM m_setup WHERE setup_id = 1) * project_value ) div 100) AS project_value_minusppn,
					project_start, project_p1, project_p2, branch_id, branch_name, div_id, div_name
					FROM t_project JOIN m_branch ON(m_branch.branch_id = t_project.m_branch_id)
					LEFT JOIN m_div ON(m_div.div_id = t_project.m_div_id)";

			if($option=='LIST'){
				$sql .=preg_match("/WHERE/i",$sql)? " AND ":" WHERE ";
				$sql .= "(lower(project_id) LIKE '%".addslashes(strtolower($filter))."%' OR
						 lower(project_flag) LIKE '%".addslashes(strtolower($filter))."%' OR
						 lower(project_code) LIKE '%".addslashes(strtolower($filter))."%' OR
						 lower(project_type) LIKE '%".addslashes(strtolower($filter))."%' OR
						 lower(project_name) LIKE '%".addslashes(strtolower($filter))."%' OR
						 lower(project_shortname) LIKE '%".addslashes(strtolower($filter))."%' OR
						 lower(project_pm) LIKE '%".addslashes(strtolower($filter))."%' OR
						 lower(project_semcm) LIKE '%".addslashes(strtolower($filter))."%' OR
						 lower(project_value) LIKE '%".addslashes(strtolower($filter))."%' OR
						 lower(project_start) LIKE '%".addslashes(strtolower($filter))."%' OR
						 lower(project_p1) LIKE '%".addslashes(strtolower($filter))."%' OR
						 lower(project_p2) LIKE '%".addslashes(strtolower($filter))."%' OR
						 lower(project_created_date) LIKE '%".addslashes(strtolower($filter))."%' OR
						 lower(project_created_by) LIKE '%".addslashes(strtolower($filter))."%' OR
						 lower(project_updated_date) LIKE '%".addslashes(strtolower($filter))."%' OR
						 lower(project_updated_by) LIKE '%".addslashes(strtolower($filter))."%' OR
						 lower(project_updated_count) LIKE '%".addslashes(strtolower($filter))."%' OR
						 lower(m_branch_id) LIKE '%".addslashes(strtolower($filter))."%' )";
			} else if($option=='SEARCH'){
				if($project_id!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_id) LIKE '%".addslashes(strtolower($project_id))."%'";
				};
				if($project_flag!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_flag) LIKE '%".addslashes(strtolower($project_flag))."%'";
				};
				if($project_code!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_code) LIKE '%".addslashes(strtolower($project_code))."%'";
				};
				if($project_type!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_type) LIKE '%".addslashes(strtolower($project_type))."%'";
				};
				if($project_name!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_name) LIKE '%".addslashes(strtolower($project_name))."%'";
				};
				if($project_shortname!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_shortname) LIKE '%".addslashes(strtolower($project_shortname))."%'";
				};
				if($project_pm!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_pm) LIKE '%".addslashes(strtolower($project_pm))."%'";
				};
				if($project_semcm!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_semcm) LIKE '%".addslashes(strtolower($project_semcm))."%'";
				};
				if($project_value!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_value) LIKE '%".addslashes(strtolower($project_value))."%'";
				};
				if($project_start!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_start) LIKE '%".addslashes(strtolower($project_start))."%'";
				};
				if($project_p1!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_p1) LIKE '%".addslashes(strtolower($project_p1))."%'";
				};
				if($project_p2!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_p2) LIKE '%".addslashes(strtolower($project_p2))."%'";
				};
				if($project_created_date!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_created_date) LIKE '%".addslashes(strtolower($project_created_date))."%'";
				};
				if($project_created_by!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_created_by) LIKE '%".addslashes(strtolower($project_created_by))."%'";
				};
				if($project_updated_date!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_updated_date) LIKE '%".addslashes(strtolower($project_updated_date))."%'";
				};
				if($project_updated_by!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_updated_by) LIKE '%".addslashes(strtolower($project_updated_by))."%'";
				};
				if($project_updated_count!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(project_updated_count) LIKE '%".addslashes(strtolower($project_updated_count))."%'";
				};
				if($m_branch!=''){
					$sql.=preg_match("/WHERE/i",$sql)?" AND ":" WHERE ";
					$sql.= " lower(m_branch_id) LIKE '%".addslashes(strtolower($m_branch))."%'";
				};
			}
			$query = $this->db->query($sql);
			return $sql;
		}

}
?>